<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
        <meta name="description" content="图腾应用登录临时中转页面">
        <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
        <meta http-equiv="Access-Control-Allow-Origin" content="*">
        <link rel="stylesheet" href="/apps/css/weui.min-2.6.4.css">
        <title>稍等片刻</title>
        <style>
            body{
                background-image: url('https://totemlife.cn/apps/public/background-2.png');
                background-repeat: no-repeat; background-size: 100% 100%;
                background-position: center center; background-size: cover; -o-background-size: cover;
                -webkit-background-size: cover; -moz-background-size: cover;
                padding-bottom: 100px; min-height: 100vh; display: flex; flex-direction: column;
            };
            .page{ min-height: 100vh; }
            .weui-msg{ min-height: 100vh; background-color:rgb(255,255,255,0); }
        </style>
    </head>
    <body ontouchstart style = "background-image: url('https://totemlife.cn/apps/default-image');">
        <div class="weui-msg">
            <div class="weui-msg__icon-area"><i class="weui-icon-success weui-icon_msg"></i></div>
            <div class="weui-msg__text-area">
                <h2 class="weui-msg__title">无限可能</h2>
                <p class="weui-msg__desc">正在为您展开</p>
            </div>
            <div class="weui-msg__opr-area">
                <p class="weui-btn_area">
                <a href="{{{nextPath}}}" class="weui-btn weui-btn_primary">欣然前往</a>
                <a id="closeWindow" href="#" class="weui-btn weui-btn_default">中止退出</a>
                </p>
            </div>
            <div class="weui-msg__extra-area">
                <a href="">用户隐私保护协议</a>
                <div class=weui-footer">
                    <div class="weui-footer__text">
                        <div>{{{nextPath}}}</div>
                        <div>Copyright© 2023 微生态临床应用前沿</div>
                        <div>技术支持：图腾生命医学研究有限公司</div>
                    </div>
                </div>
            </div>
            <div role="alert" id="loadingToast">
                <div class="weui-mask_transparent"></div>
                <div class="weui-toast">
                    <span class="weui-primary-loading weui-icon_toast">
                      <span class="weui-primary-loading__dot"></span>
                    </span>
                    <p class="weui-toast__content">自动跳转中！</p>
                </div>
            </div>
        </div>
        <script>
            try{
                localStorage.setItem("totemUID", "{{totemUID}}");
                localStorage.setItem("rid", "{{rid}}");
                /*
                const okeyMsg = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxXXXXXXXXXXXXXX';
                const body =  JSON.stringify({totemUID:1, href: window.location.href, memo: `set localStroage OKEY: ${okeyMsg}`});
                const response = fetch('/apps/wx-client-hook', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body});
                */
            } catch(e) {
                const errMsg = JSON.stringfy(e);
                const errBody = JSON.stringify({totemUID, href: window.location.href, memo: `set localStroage XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxXXXXXXX: ${errMsg}`});
                const response = fetch('/apps/wx-client-hook', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: errBody });
            }

            // 获取nextPath，并检查是否包含'mtx.totemlife.cn'
            let nextPath = "{{{nextPath}}}";
            const url = new URL(nextPath, window.location.origin);
            const hasRft = url.searchParams.has('rft');

            // 如果nextPath包含'mtx.totemlife.cn'，并且查询参数中没有'rft'
            if (nextPath.includes('mtx.totemlife.cn') && !hasRft) {
                // 添加'&rft={{rid}}'到nextPath
                url.searchParams.set('rft', "{{rid}}");
                nextPath = url.toString();
            }
            // 使用修改后的nextPath进行跳转
            // window.location.href=nextPath;
            // 添加一个极短的延迟，确保 localStorage 写入完成
            setTimeout(() => {
                window.location.href = nextPath;
            }, 100); // 100ms 延迟

        </script>
    </body>
</html>
